<template>
  <div class="settings-view">
    <div class="container">
      <header class="page-header">
        <h1>游戏设置</h1>
        <router-link to="/" class="back-btn">
          <i class="icon-arrow-left"></i>
          返回
        </router-link>
      </header>
      
      <SettingsPanel @settings-changed="handleSettingsChanged" />
    </div>
  </div>
</template>

<script setup lang="ts">
import SettingsPanel from '@/components/SettingsPanel.vue'
import type { GameSettings } from '@/stores/gameStore'

/**
 * 设置视图组件
 * 提供设置页面的布局和导航
 * @component
 */

/**
 * 处理设置变化事件
 * @param settings - 更新后的设置
 */
const handleSettingsChanged = (settings: GameSettings): void => {
  console.log('设置已更新:', settings)
}
</script>

<style lang="scss" scoped>
.settings-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 0;
  margin: 0;
  overflow: hidden;
  z-index: 1000;

  .container {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    
    @include mobile-all {
      padding: env(safe-area-inset-top, 1rem) env(safe-area-inset-right, 1rem) env(safe-area-inset-bottom, 1rem) env(safe-area-inset-left, 1rem);
      max-width: none;
      width: 100%;
      height: 100%;
    }
    
    @include mobile-small {
      padding: env(safe-area-inset-top, 0.5rem) env(safe-area-inset-right, 0.5rem) env(safe-area-inset-bottom, 0.5rem) env(safe-area-inset-left, 0.5rem);
    }
  }

  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;

    h1 {
      color: white;
      font-size: 2.5rem;
      font-weight: bold;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    }

    .back-btn {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.75rem 1.5rem;
      background: rgba(255, 255, 255, 0.2);
      color: white;
      text-decoration: none;
      border-radius: $border-radius-md;
      transition: $transition-normal;

      &:hover {
        background: rgba(255, 255, 255, 0.3);
        transform: translateY(-2px);
      }

      .icon-arrow-left::before {
        content: '←';
      }
    }
  }

  .settings-content {
    .settings-section {
      background: rgba(255, 255, 255, 0.95);
      border-radius: $border-radius-lg;
      padding: 2rem;
      margin-bottom: 2rem;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

      h2 {
        color: $text-color;
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid $primary-color;
      }

      .settings-group {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;

        .setting-item {
          .setting-label {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: 500;
            color: $text-color;

            span {
              font-size: 1rem;
            }
          }

          .setting-description {
            margin-top: 0.5rem;
            font-size: 0.8rem;
            color: lighten($text-color, 20%);
          }

          // 开关样式
          .toggle-switch {
            position: relative;
            width: 50px;
            height: 24px;

            input {
              opacity: 0;
              width: 0;
              height: 0;

              &:checked + .slider {
                background-color: $primary-color;

                &:before {
                  transform: translateX(26px);
                }
              }
            }

            .slider {
              position: absolute;
              cursor: pointer;
              top: 0;
              left: 0;
              right: 0;
              bottom: 0;
              background-color: #ccc;
              transition: 0.4s;
              border-radius: 24px;

              &:before {
                position: absolute;
                content: "";
                height: 18px;
                width: 18px;
                left: 3px;
                bottom: 3px;
                background-color: white;
                transition: 0.4s;
                border-radius: 50%;
              }
            }
          }

          // 音量控制
          .volume-control,
          .sensitivity-control {
            display: flex;
            align-items: center;
            gap: 1rem;
            min-width: 200px;

            .volume-slider,
            .sensitivity-slider {
              flex: 1;
              height: 6px;
              border-radius: 3px;
              background: #ddd;
              outline: none;
              cursor: pointer;

              &::-webkit-slider-thumb {
                appearance: none;
                width: 18px;
                height: 18px;
                border-radius: 50%;
                background: $primary-color;
                cursor: pointer;
              }

              &::-moz-range-thumb {
                width: 18px;
                height: 18px;
                border-radius: 50%;
                background: $primary-color;
                cursor: pointer;
                border: none;
              }
            }

            .volume-value,
            .sensitivity-value {
              min-width: 40px;
              text-align: center;
              font-weight: 500;
              color: $primary-color;
            }
          }

          // 选择框样式
          .control-select,
          .difficulty-select {
            padding: 0.5rem 1rem;
            border: 2px solid #ddd;
            border-radius: $border-radius-md;
            background: white;
            color: $text-color;
            font-size: 1rem;
            cursor: pointer;
            transition: $transition-normal;

            &:focus {
              outline: none;
              border-color: $primary-color;
            }
          }

          // 按键绑定
          .key-bindings {
            h3 {
              color: $text-color;
              margin-bottom: 1rem;
              font-size: 1.2rem;
            }

            .key-binding-list {
              display: flex;
              flex-direction: column;
              gap: 0.75rem;

              .key-binding-item {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 0.75rem;
                background: rgba($primary-color, 0.05);
                border-radius: $border-radius-md;

                .action-name {
                  font-weight: 500;
                  color: $text-color;
                }

                .key-button {
                  padding: 0.5rem 1rem;
                  border: 2px solid $primary-color;
                  background: white;
                  color: $primary-color;
                  border-radius: $border-radius-sm;
                  cursor: pointer;
                  transition: $transition-normal;
                  min-width: 100px;
                  font-weight: 500;

                  &:hover {
                    background: $primary-color;
                    color: white;
                  }

                  &.recording {
                    background: $primary-color;
                    color: white;
                    animation: pulse 1s infinite;
                  }
                }
              }
            }
          }

          // 数据操作按钮
          .data-actions {
            display: flex;
            gap: 1rem;
            flex-wrap: wrap;

            .btn {
              padding: 0.75rem 1.5rem;
              border: none;
              border-radius: $border-radius-md;
              cursor: pointer;
              transition: $transition-normal;
              font-weight: 500;

              &.btn-secondary {
                background-color: $secondary-color;
                color: white;

                &:hover {
                  background-color: darken($secondary-color, 10%);
                  transform: translateY(-2px);
                }
              }

              &.btn-danger {
                background-color: $danger-color;
                color: white;

                &:hover {
                  background-color: darken($danger-color, 10%);
                  transform: translateY(-2px);
                }
              }
            }
          }
        }
      }
    }
  }

  .settings-footer {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;

    .btn {
      padding: 1rem 2rem;
      border: none;
      border-radius: $border-radius-lg;
      cursor: pointer;
      transition: $transition-normal;
      font-size: 1.1rem;
      font-weight: 500;

      &.btn-primary {
        background-color: $primary-color;
        color: white;

        &:hover {
          background-color: darken($primary-color, 10%);
          transform: translateY(-2px);
        }
      }

      &.btn-secondary {
        background-color: $secondary-color;
        color: white;

        &:hover {
          background-color: darken($secondary-color, 10%);
          transform: translateY(-2px);
        }
      }
    }
  }

  // 确认对话框
  .confirm-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;

    .confirm-dialog {
      background: white;
      padding: 2rem;
      border-radius: $border-radius-lg;
      max-width: 400px;
      width: 90%;
      text-align: center;

      h3 {
        color: $text-color;
        margin-bottom: 1rem;
        font-size: 1.5rem;
      }

      p {
        color: lighten($text-color, 20%);
        margin-bottom: 2rem;
        line-height: 1.5;
      }

      .dialog-buttons {
        display: flex;
        gap: 1rem;
        justify-content: center;

        .btn {
          padding: 0.75rem 1.5rem;
          border: none;
          border-radius: $border-radius-md;
          cursor: pointer;
          transition: $transition-normal;
          font-weight: 500;

          &.btn-danger {
            background-color: $danger-color;
            color: white;

            &:hover {
              background-color: darken($danger-color, 10%);
            }
          }

          &.btn-secondary {
            background-color: $secondary-color;
            color: white;

            &:hover {
              background-color: darken($secondary-color, 10%);
            }
          }
        }
      }
    }
  }
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

// 响应式设计
@media (max-width: $breakpoint-md) {
  .settings-view {
    padding: 1rem;

    .page-header {
      flex-direction: column;
      gap: 1rem;
      text-align: center;

      h1 {
        font-size: 2rem;
      }
    }

    .settings-section {
      padding: 1.5rem;

      .setting-item {
        .setting-label {
          flex-direction: column;
          align-items: flex-start;
          gap: 0.5rem;
        }

        .volume-control,
        .sensitivity-control {
          min-width: auto;
        }

        .data-actions {
          flex-direction: column;

          .btn {
            width: 100%;
          }
        }

        .key-binding-list {
          .key-binding-item {
            flex-direction: column;
            gap: 0.5rem;
            text-align: center;

            .key-button {
              width: 100%;
            }
          }
        }
      }
    }

    .settings-footer {
      flex-direction: column;

      .btn {
        width: 100%;
      }
    }
  }
}
</style>